<template>
	<view>
		<u-popup :show="show" @close="close" mode="center" :round="10">
			<view class="mainpadding">
				<view class="sanshier textcenter fonweight zhonghei">追评</view>
				<textarea class="textarea margin_top" placeholder="请输入内容" v-model="zp_content"></textarea>
				<view class="flexbetween margin_top">
					<view class="qxdtn flexcenter margin_right" @click="close">取消</view>
					<view class="qubtn flexcenter" @click="zhuiping(currentid)">确认</view>
				</view>
			</view>
		</u-popup>
		<view class="tab_nav">
			<view class="navTitle" v-for="(item,index) in navList" :key="index">
				<view :class="{'active':isActive === index}" @click="checked(index)">
					{{item.title}}
				</view>
			</view>
		</view>
		<view class="mainpadding2">
			<view class="mainpadding radius ffffff margin_top" v-for="(item,index) in list.data" :key="item.id">
				<view class="flexbetween">
					<view class="flexleft">
						<image class="touxiag margin_right2" :src="item.user.avatar_text" mode=""></image>
						<view class="">
							<view class="zhonghei sanshier ">{{item.user.nickname}}</view>
							<view class="xiaohui ershil margin_top1 ">{{item.createtime_text}}</view>
						</view>
					</view>
					<u-rate :value="item.star" activeColor="#ff9341" readonly></u-rate>
				</view>
				<view class="xiaohui ershiba margin_top">{{item.content}}</view>
				<template v-if="item.video_url_text">
					<video class="scyyzz margin_top" :id="'video'+index" :src="item.video_url_text"
						@play="videoplay(index)"></video>
				</template>
				<view class="flexleft flex_wrap pdl">
					<view class="flexcenter tpbox " v-for="(ite,ind) in item.images_text" :key="ind">
						<view class="tjtp">
							<image class="" :src="ite" mode="" @click="lbtpriview(ind,item.images_text)"></image>
						</view>
					</view>
				</view>
				<view class="huibox margin_top mainpadding" v-if="item.reply_content">
					<view class="xiaohui ershiba">商家回复：
						<text class="xiaohei ershiba">{{item.reply_content}}</text>
					</view>
				</view>
				<view class="huibox margin_top mainpadding" v-if="item.zp_content">
					<view class="xiaohui ershiba">追评：
						<text class="xiaohei ershiba">{{item.zp_content}}</text>
					</view>
				</view>
				<view class="flexright margin_top">
					<view class="zuixbtn flexcenter margin_right" @click="deleteorderth(item.id)">删除</view>
					<view class="scbtn flexcenter" @click="currentid=item.id;show=true" v-if="!item.zp_content">追评</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				isActive: 0,
				navList: [{
					index: 0,
					title: '酒店评价'
				}, {
					index: 1,
					title: "商品评价"
				}],
				show: false,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				changePlay:false,
				currentid:"",
				zp_content:""
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			zhuiping(id) {
				let url = "/api/user/hotelCommentZp"
				if(this.isActive==1){
					url = "/api/user/goodsCommentZp"
				}
				if(this.zp_content==""){
					httpRequest.toast("请输入追评内容")
					return false
				}
				this.show = false
				httpRequest.request(url, 'GET', {
					id: id,
					zp_content:this.zp_content
				}).then(res => {
					this.zp_content = ""
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			deleteorderth(id) {
				httpRequest.modal('提示', '是否确认删除当前评价', true, (resp) => {
					if (resp) {
						let url = "/api/user/deleteHotelComment"
						if(this.isActive==1){
							url = "/api/user/deleteGoodsComment"
						}
						httpRequest.request(url, 'GET', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							if(res.code==1){
								this.init()
							}
						})
					}
				})
			},
			videoplay(index) {
				let _this = this;
				//全局变量changePlay表示正在切换。每次切换完播放等一秒在恢复，解决Android下的问题
				if (this.changePlay) {
					return
				}
				_this.changePlay = true
				let currentIndex = 'video' + index; // 获取当前视频索引
				console.log("playVideo currentIndex ", currentIndex)
				// 获取视频列表
				this.list.data.forEach((item, index) => { // 获取json对象并遍历, 停止非当前视频
					if (item.video_url_text) {
						let temp = 'video' + index;
						if (temp != currentIndex) { //判断名字是否一致
							// 暂停其余视频
							console.log(temp, currentIndex, '暂停播放');
							uni.createVideoContext(temp, _this).pause(); //暂停视频播放事件
						}
					}
			
				})
				setTimeout(() => {
					_this.changePlay = false
				}, 1000)
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/user/hotelCommentIndex"
				let data = {
					page: page || 1,
					limit: _this.limit,
				}
				if(this.isActive==1){
					url="/api/user/goodsComment"
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			close() {
				this.show = false
			},
			checked(index) {
				this.isActive = index
				this.videoplay("pause")
				this.init()
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	.scyyzz {
		width: 100%;
		height: 291rpx;
	}
	.touxiag {
		width: 73rpx;
		height: 73rpx;
		border-radius: 50%;
	}
	.tpbox {
		width: 33.33%;
		margin-top: 30rpx;
	}
	
	.tjtp {
		width: 209rpx;
		height: 209rpx;
		position: relative;
	
		image {
			border-radius: 10rpx;
			width: 100%;
			height: 100%;
		}
	}
	.qubtn{
		width: 265rpx;
		height: 81rpx;
		background-color: #FF9341;
		border: 1rpx solid #FF9341;
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC;
		border-radius: 51rpx;
		font-weight: 500;
		color: #FFFFFF;
	}
	.qxdtn{
		width: 265rpx;
		height: 81rpx;
		border: 1rpx solid #FF9341;
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC;
		border-radius: 51rpx;
		font-weight: 500;
		color: #FF9341;
	}
	.textarea {
		height: 372rpx;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		box-sizing: border-box;
		width: 100%;
		padding: 30rpx;
		border: 1rpx solid #DFDFDF;
	}
	.scbtn {
		width: 94rpx;
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF9341;
		border: 1rpx solid #FF9341;
		height: 46rpx;
		border-radius: 84rpx;
	}

	.zuixbtn {
		border-radius: 84rpx;
		width: 94rpx;
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #666666;
		border: 1rpx solid #666666;
		height: 46rpx;
	}

	.mdtp {
		width: 74rpx;
		height: 74rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}

	.huibox {
		padding: 10rpx;
		background: #F8F8F8;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}

	.tupian {
		width: 140rpx;
		height: 140rpx;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
	}

	.touxiang {
		width: 73rpx;
		height: 73rpx;
		border-radius: 50%;
	}

	.tab_nav {
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: 11rpx;
	}

	.tab_nav .navTitle {
		height: 76rpx;
		line-height: 76rpx;
		width: 100%;
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #999999;
	}

	.active {
		font-size: 30rpx;
		color: #333333;
		font-weight: bold;
		position: relative;
	}

	.active::after {
		content: "";
		position: absolute;
		width: 61rpx;
		height: 6rpx;
		background: #FFB800;
		border-radius: 9rpx;
		background-size: 100% 100%;
		left: 0rpx;
		right: 0rpx;
		bottom: 0rpx;
		margin: auto;
	}
</style>